package com.matt.domain.courseV2;

import com.matt.commons.model.Domain;
import com.matt.foundation.vo.course.VendorCoursePrepareDetailVO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.beanutils.BeanUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;

/**
 * 备课信息，老师应当在上课之前，可以对课程教学内容进行修改，并创建副本以保存记录。
 */
@Table(name = "tc_vendor_prepared_course")
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
public class VendorPreparedCourse extends Domain implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name = "published")
    private Boolean published = Boolean.FALSE;

    @Column(name = "title", nullable = false)
    private String title;

    @Column(name = "vendor_course_id", nullable = false)
    private String vendorCourseId;

    @Column(name = "author")
    private String author;

    @Column(name = "authorId")
    private String authorId;

    @Column(name = "last_updated")
    private Timestamp lastUpdated ;

    /**
     * 附件列表JSON [{ "name":"", "type":"",url:""}]
     */
    @Column(name = "attachments")
    private String attachments;

    /**
     * 教具列表 [{ "name":"", "count":"","unit":"",img:""}]
     */
    @Column(name = "tools")
    private String tools;

    @Column(name = "tags")
    private String tags;

    /**
     * 教学提升领域
     */
    @Column(name = "dimensions")
    private String dimensions;

    @Column(name = "guideVideo")
    private String guideVideo;

    /**
     * 内容
     */
    @Column(name = "content", nullable = false)
    private String content;

    /**
     * 备注
     */
    @Column(name = "comment")
    private String comment;

    /**
     * 教学指导文字版
     */
    @Column(name = "guideText")
    private String guideText;

    /**
     * 关联书籍
     */
    @Column(name = "ref_books")
    private String refBooks;

    @Column(name = "content_template", nullable = false)
    private String template;;

    public VendorPreparedCourse merge(VendorCoursePrepareDetailVO prepareDetail){

        try {
            BeanUtils.copyProperties(this, prepareDetail);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return this;
    }

    public static VendorPreparedCourse of(VendorCoursePrepareDetailVO prepareDetail){
        VendorPreparedCourse vpc = new VendorPreparedCourse();

        return vpc.merge(prepareDetail);
    }
}